<%@ page contentType="text/html;charset=UTF-8" %>

<html>
<head>
	<title>数据字典管理</title>
	<%@ include file="/common/meta.jsp" %>
    <%@ include file="/common/import.jsp" %>
    <!-- 
	<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/js/easyui/themes/demo.css">
	 -->
	<script type="text/javascript">
		$(function(){
			$('#dataCateList').datagrid({
				title:'科目列表',
				iconCls:'icon-ok',
				url:'${ctx }/dict/cate/list!data.action',
				nowrap: false,
				striped: true,
				collapsible:false,				
				fitColumns: true,
				pagination:true,
				singleSelect:true,
				rownumbers:true,
				remoteSort: false,
				pageList:[15,20,30,50],
				idField:'cateId',
				columns:[[
					{field:'cateCname',title:'科目名称',width:100,sortable:true},
					{field:'cateEname',title:'科目标识',width:100,sortable:true},
					{field:'cateStatus',title:'状态',width:50,sortable:true,
						formatter:function(value){
							if( value=='1'){return '<font color=blue>启用</font>';}
							else{ return '<font color=red>停用</font>';}
						}
					},
					{field:'cateRemark',title:'描述',width:100,sortable:true}
				]],
				toolbar:[{
					text:'增加',
					iconCls:'icon-add',
					handler:function(){
						saveCate();
					}
				},'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						deleteCate();
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						editCate();
					}
				},'-',{
					text:'查找',
					iconCls:'icon-search',
					handler:function(){
						$('#query').window('open');
						$('#cateCname').focus();
					}
				},'-',{
					text:'刷新',
					iconCls:'icon-reload',
					handler:function(){
						$('#dataCateList').datagrid('reload');
					}
				}				
				,'-',
		          {
		              text:'条目管理',
		              iconCls:'icon-dict',
		              handler:function(){
		        	  	//dataItemList();
		                  dataItemTree();
		              }
		          }
				],
				onDblClickRow:function(){
					dataItemTree();
				}	
			});		
		});
		
		// 查找
		function searchCate(){
			var queryParams = $('#dataCateList').datagrid('options').queryParams;	       
	        queryParams.cateEname = $('#cateEname').val();
	        queryParams.cateCname = $('#cateCname').val();
	        var options = $('#dataCateList').datagrid('getPager').data("pagination").options;  
	        options.pageNumber=1;  
	        options.total=0;  
	        options.pageSize=15; 
	        $('#dataCateList').datagrid("reload");
	        $('#query').window('close');
		}
		
		// 进入增加页面
		function saveCate(){
			$('#saveFrame').html('');			
			var url = '${ctx}/dict/cate/add.action';				
			$('#saveFrame').attr("title",'');
			$('#saveFrame').attr("src",url);
			$('#saveDiv').window('open');			
		}
		
		
		// 点击取消按钮，关闭添加窗口
		function colseAdd(){
			$('#saveDiv').window('close');
		}
		
		// 刷新列表
		function cateReload(){
			$('#dataCateList').datagrid('reload');
		}
		
		// 判断是否选中一条记录
		function getSelected(){
			var selected = $('#dataCateList').datagrid('getSelected');
			if (selected){
				return selected;
			}else{
				$.messager.alert('提示', '请选择要操作的数据', 'info');
			}
		}
		
		// 进入修改页面
		function editCate(){
			var node = getSelected();		
			if (node){	
				var url = '${ctx}/dict/cate/edit.action?id='+node.cateId;
				$('#saveFrame').attr("title",node.cateCname);
				$('#saveFrame').attr("src",url);
				$('#saveDiv').window('open');
			}
		}
		
		//删除，物理删除
		function deleteCate(){					
			var node = getSelected();	
			if(node){
		    	$.messager.confirm('确认','您确定要删除:<font color=red>'+node.cateCname+'</font> ？',function(r){
		        	if(r){
						$.ajax({
							type: "post",
							url: "${ctx}/dict/cate/del.action?id="+node.cateId+"&cateEname="+node.cateEname,
							dataType: "json",
							success: function(data){
								var result = jQuery.parseJSON(data);
	    						if(result.flag=='T'){
									$.messager.alert('结果', '操作成功', 'info');	
								    var rowIndex = $('#dataCateList').datagrid('getRowIndex',node);								
								    $('#dataCateList').datagrid('deleteRow', rowIndex);	
	    						}else if(result.flag=='H'){
	    							$.messager.alert('结果', result.msg, 'info');	
	    						}else{
	    							$.messager.alert('结果', '操作失败，请重试', 'error');	
	    						}
							},
							error:function(messg)  { 
					       	    $.messager.alert('错误提示', '操作失败:'+messg.responseText, 'error');
					       } 
						});
		          	}
		       });		             		
		    }	
		}
		
		// 条目管理
		function dataItemTree(){
		    var node = getSelected();
		    if(node){		    
				$('#dataItemFrame').html('');
				var cateEname= node.cateEname;
				var url = '${ctx}/dict/item/tree.action?cateEname='+cateEname;											
				$('#dataItemFrame').attr("src",url);
			    $('#dataItemWin').window('open');
			    $('#dataItemWin').window('setTitle','字典条目管理[<font color=red>'+node.cateCname+'</font>]');
		    }		
		}

	</script>
</head>
<body>

	<table id="dataCateList"></table>
	
	<!-- 添加窗口 -->
	<div id="saveDiv" class="easyui-window" title="科目定义" style="padding:5px;width: 500px;height:250px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="saveFrame" height="100%" width="100%" scrolling="No" frameborder="0" ></iframe>
    </div>
    
    <!-- 字典条目管理窗口 -->
    <div id="dataItemWin" class="easyui-window" title="字典条目管理" style="padding:5px;width: 700px;height:400px;top: 62px;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
   		<iframe frameborder="0"  id="dataItemFrame" height="100%" width="100%" scrolling="yes" frameborder="0" ></iframe>
    </div>
    
    <!-- 查询窗口 -->
	<div id="query" class="easyui-window" title="查询" style="padding:5px;width:400px;height:250;"
    	iconCls="icon-search" closed="true" maximizable="false" minimizable="false" collapsible="false">
		<table class="datagrid-body" >
			<tr>	
				<td class="datagrid-header">科目名称：</td>
				<td><input type="text" id="cateCname" name="cateCname" size="30" value="" /></td>
			</tr>
			
			<tr >
				<td class="datagrid-header">科目标识：</td>
				<td><input type="text" id="cateEname" name="cateEname" size="30" value="" /></td>
			</tr>
			<!--
			<tr>
			<td class="datagrid-header">状态</td>
				<td>
				<input type="radio" name="cateStatus" id="cateStatus_1" value="1" />启用
				<input type="radio" name="cateStatus"  id="cateStatus_0" value="0" />停用
				</td>
			</tr>
			-->
			<tr>	
				<td class="datagrid-header"></td>
				<td><a href="#" class="easyui-linkbutton" iconCls="icon-search" onClick="searchCate();">查找</a></td>	
			</tr>
		</table>
    </div>
</body>
</html>